<template>
    <div>
        <div class="breadcrumb-box">
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item :to="{ path: '/noStandCustomIndex' }">非标定制</el-breadcrumb-item>
                <el-breadcrumb-item>新增非标定制</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="line">
            <img :src="$global.Image.icon_goods_line" />
        </div>
        <div class="container">
            <div class="line-ti">
                <div>新增非标定制</div>
            </div>
            <div class="write-info-tit">
                填写非标定制信息
            </div>
            <el-form ref="form" :model="form" label-width="120px">
                <el-form-item label="联系人：" prop="contacts">
                    <el-input v-model="form.contacts" placeholder="请输入联系人"></el-input>
                </el-form-item>
                <el-form-item label="联系电话：" prop="mobile">
                    <el-input v-model="form.mobile" placeholder="请输入联系电话"></el-input>
                </el-form-item>
                <el-form-item label="商品名称：" prop="name">
                    <el-input v-model="form.name" placeholder="请输入商品名称"></el-input>
                </el-form-item>
                <el-form-item label="功能需求：" prop="content">
                    <el-input type="textarea" v-model="form.content" placeholder="请输入功能需求"></el-input>
                </el-form-item>
                <el-form-item label="参数需求：" prop="content1">
                    <el-input type="textarea" v-model="form.content1" placeholder="请输入参数需求"></el-input>
                </el-form-item>
                <el-form-item label="">
                    <div class="file">
                        <div class="file-left">附件</div>
                        <div class="td-f1">
                            <div class="el-form-item__content upload-img">
                                <el-upload
                                    ref="upload"
                                    :action="url"
                                    :data="qiniuData"
                                    :on-preview="handlePictureCardPreview"
                                    :before-upload="beforeAvatarUpload"
                                    :on-remove="handleRemove"
                                    :on-success="handleAvatarSuccess"
                                    :multiple="true"
                                    name="files[]"
                                >
                                    <el-button size="small" type="primary">点击上传</el-button>
                                </el-upload>
                            </div>
                        </div>
                    </div>
                </el-form-item>
                <el-form-item>
                    <el-button type="success" @click="onSubmit('form')">提交</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
import { articlePublish } from "@api/order";
import uploadQiniu from "@/mixins/uploadQiniu"
export default {
    mixins: [uploadQiniu],
    data() {
        return {
            type: 3,
            form: {
                contacts: "",//联系人
                mobile: "",// 联系电话
                name: "",//商品名称
                brand: "",//品牌品牌
                content: "",//型号
                content1: "",//参数
            },
            files: [],
            rules: {
                contacts: [
                    {
                        required: true,
                        message: "请输入联系人",
                        trigger: "blur",
                    },
                ],
                mobile: [
                    {
                        required: true,
                        message: "请输入联系电话",
                        trigger: "blur",
                    },
                ],
                name: [
                    {
                        required: true,
                        message: "请输入商品名称",
                        trigger: "blur",
                    },
                ],
                content: [
                    {
                        required: true,
                        message: "请输入功能需求",
                        trigger: "blur",
                    },
                ],
                content1: [
                    {
                        required: true,
                        message: "请输入参数需求",
                        trigger: "blur",
                    },
                ],
            },
        };
    },
    methods: {
        onSubmit(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.submit();
                } else {
                    return false;
                }
            });
        },
        async submit() {
            let imgs  = []
            imgs = this.formatFile(this.fileList)
            if (!imgs.length) {
                that.$dialog.error('请上传附件')
                return
            };
            try {
                let that = this,
                    params = that.form;
                    params.type = that.type
                    params.files = JSON.stringify(imgs)
                console.log('params', params)
                articlePublish(params)
                    .then(function (res) {
                        if (res.status != 200) {
                            that.$dialog.toast({ mes: res.msg });
                            return;
                        }
                        that.$dialog.toast({ mes: res.msg });
                        that.$router.go(-1)
                    })
                    .catch((err) => {
                        that.$dialog.error(err.msg);
                    });
            } catch (e) {
                this.$dialog.error(e.msg);
            }
        },
    },
    mounted() {},
};
</script>

<style scoped  lang="scss">
@import '../../assets/css/common/create.scss';
</style>